package com.yanqu.road.server.cmd.tradewar;

import com.yanqu.road.pb.tradewar.TradeWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.TradeWarModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

@Cmd(code = Protocol.S_TRADE_WAR_BUY_BUFF, desc = "商战购买buff")
public class TradeWarBuyBuffCmd extends AbstractCommand {

	private int times;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		TradeWarProto.TradeWarBuyBuffReqMsg reqMsg = TradeWarProto.TradeWarBuyBuffReqMsg.parseFrom(packet.getBytes());
		times = reqMsg.getBuyTimes();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ret = player.getModule(TradeWarModule.class).buyBuff(times);
	}

	@Override
	public void sendData(GamePlayer player) {
		TradeWarProto.TradeWarBuyBuffRespMsg.Builder respMsg = TradeWarProto.TradeWarBuyBuffRespMsg.newBuilder();
		respMsg.setRet(ret);
		respMsg.setTotalBuyTimes(player.getModule(TradeWarModule.class).getUserTradeWarBattle().getBuyBuffTimes());
		player.sendPacket(Protocol.U_TRADE_WAR_BUY_BUFF, respMsg);
	}
}
